import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { RoleMenu } from './role-menu.entity';

@Entity('menus')
export class Menu {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: number;

  @Column({ type: 'varchar', length: 100, comment: '菜单名称' })
  name: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '菜单路径' })
  path?: string;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '组件路径' })
  component?: string;

  @Column({ type: 'varchar', length: 50, nullable: true, comment: '菜单图标' })
  icon?: string;

  @Column({ type: 'bigint', nullable: true, comment: '父菜单ID' })
  parentId?: number;

  @Column({ type: 'varchar', length: 50, comment: '菜单类型：menu-菜单，button-按钮' })
  type: string;

  @Column({ type: 'tinyint', default: 1, comment: '状态：1-显示，0-隐藏' })
  visible: number;

  @Column({ type: 'tinyint', default: 1, comment: '状态：1-启用，0-禁用' })
  status: number;

  @Column({ type: 'int', default: 0, comment: '排序' })
  sort: number;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '备注' })
  remark?: string;

  @CreateDateColumn({ comment: '创建时间' })
  createTime: Date;

  @UpdateDateColumn({ comment: '更新时间' })
  updateTime: Date;

  @ManyToOne(() => Menu, menu => menu.children, { nullable: true })
  @JoinColumn({ name: 'parent_id' })
  parent?: Menu;

  @OneToMany(() => Menu, menu => menu.parent)
  children: Menu[];

  @OneToMany(() => RoleMenu, roleMenu => roleMenu.menu)
  roleMenus: RoleMenu[];
}